package com.dodock.generic.helper;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class ExtraMainSiteHeadlinesExtractor {

	
	public static ArrayList<HashMap<String, String>> getHeadlines(String url){
		
		ArrayList<HashMap<String, String>> headlines = new ArrayList<HashMap<String,String>>();
		try{
		
		
			Document doc = Jsoup.connect(url).get();
			//<div class="threeCol mb20 white">
			Element masthead = doc.select("div[class=threeCol mb20 white]").first();
			Elements links = masthead.select("a[href]");
			ArrayList<String> list = new ArrayList<String>();
			
			for(Element a:links){
				String href = a.attr("href");
				
				if(href.startsWith("/detail/")){
					String id = href.substring(href.lastIndexOf('/') + 1);
					if(list.contains(id) == false){
						String text = a.text();
						HashMap<String, String> news = new HashMap<String, String>();
						news.put("news", text);
						news.put("id", id);
						headlines.add(news);
						list.add(id);
					}
				}
			}
		
		}
		catch(Exception ex){
			
		}
		
		return headlines;
	}
	
}
